package cs236703.winter2013.hw4.tests;

import cs236703.winter2013.hw4.provided.JAssertionError;
import cs236703.winter2013.hw4.solution.JBefore;
import cs236703.winter2013.hw4.solution.JCore;
import cs236703.winter2013.hw4.solution.JSetup;
import cs236703.winter2013.hw4.solution.JTest;
import cs236703.winter2013.hw4.solution.JTestClass;

public @JTestClass class MyClass {
	protected boolean setup1, setup2, setup3, before1, beforeOverride,
		test1, override, usingDerived;
	protected String loc, faulty = "";
	
	public @JTest void test1() throws JAssertionError {
		if(!before1 || test1 || !faulty.isEmpty()) {
			String reason = faulty;
			faulty = "";
			JCore.assertEquals("test1 reason: " + reason, false);
		}
		test1 = true;
		before1 = false;
		if(usingDerived)
			beforeOverride = false;
	}
	
	public @JSetup void setup1() {
		setup1 = true;
		before1 = beforeOverride = test1 = override = false;
	}
	
	private @JSetup void setup2() {
		setup2 = true;
	}
	
	protected @JBefore({"test1", "pointless", "override"}) void before1() {
		if(!(setup1 && setup2) || (usingDerived && !setup3) || before1)
			faulty = "before1";
		before1 = true;
	}
	
	protected @JBefore({"override"}) void beforeOverride() {
		if(!(setup1 && setup2) || (usingDerived && !setup3) || beforeOverride)
			faulty = "beforeOverride";
		beforeOverride = true;
		loc = "base";
	}
	
	public @JTest void override() throws JAssertionError {
		if(!before1 || !before1 || !beforeOverride || override || !faulty.isEmpty()) {
			String reason = faulty;
			faulty = "";
			JCore.assertEquals("override reason: " + reason, false);
		}
		JCore.assertEquals("base", loc);
		override = true;
		before1 = beforeOverride = false;
	}
	
	public void noTest() throws JAssertionError {
		JCore.assertEquals("noTest", false);
	}
	
	private @JTest void throwsAssertionError() throws JAssertionError {
		throw new JAssertionError("throw assertion", false);
	}
	
	private @JTest void throwsError() throws Exception {
		throw new Exception("test threw an error");
	}
}
